package com.ts.animal.controller;

import com.ts.animal.domain.RfidSyncDataHistoryDO;
import com.ts.animal.service.RfidSyncDataHistoryService;
import com.ts.common.utils.PageUtils;
import com.ts.common.utils.Query;
import com.ts.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 标签（动物状态）同步历史数据表
 *
 * @author bobby
 * @email bobby@126.com
 * @date 2022-10-11 20:51:56
 */

@Controller
@RequestMapping("/animal/rfidSyncDataHistory")
public class RfidSyncDataHistoryController {
    @Autowired
    private RfidSyncDataHistoryService rfidSyncDataHistoryService;

    @GetMapping()
    @RequiresPermissions("animal:rfidSyncDataHistory:rfidSyncDataHistory")
    String RfidSyncDataHistory() {
        return "animal/rfidSyncDataHistory/rfidSyncDataHistory";
    }

    @ResponseBody
    @RequestMapping("/list")
    @RequiresPermissions("animal:rfidSyncDataHistory:rfidSyncDataHistory")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<RfidSyncDataHistoryDO> rfidSyncDataHistoryList = rfidSyncDataHistoryService.list(query);
        int total = rfidSyncDataHistoryService.count(query);
        PageUtils pageUtils = new PageUtils(rfidSyncDataHistoryList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("animal:rfidSyncDataHistory:add")
    String add() {
        return "animal/rfidSyncDataHistory/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("animal:rfidSyncDataHistory:edit")
    String edit(@PathVariable("id") Long id, Model model) {
        RfidSyncDataHistoryDO rfidSyncDataHistory = rfidSyncDataHistoryService.get(id);
        model.addAttribute("rfidSyncDataHistory", rfidSyncDataHistory);
        return "animal/rfidSyncDataHistory/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("animal:rfidSyncDataHistory:add")
    public Result save(RfidSyncDataHistoryDO rfidSyncDataHistory) {
        Result result = Result.ok();
        rfidSyncDataHistoryService.save(result, rfidSyncDataHistory);
        return result;
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("animal:rfidSyncDataHistory:edit")
    public Result update(RfidSyncDataHistoryDO rfidSyncDataHistory) {
        Result result = Result.ok();
        rfidSyncDataHistoryService.update(result, rfidSyncDataHistory);
        return result;
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("animal:rfidSyncDataHistory:remove")
    public Result remove(Long id) {
        Result result = Result.ok();
        rfidSyncDataHistoryService.remove(result, id);
        return result;
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("animal:rfidSyncDataHistory:batchRemove")
    public Result remove(@RequestParam("ids[]") Long[] ids) {
        Result result = Result.ok();
        rfidSyncDataHistoryService.batchRemove(result, ids);
        return result;
    }

}
